package com.atguigu.tingshu.search.api;

import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author atguigu-mqx
 * @ClassName Demo
 * @description: TODO
 * @date 2024年04月13日
 * @version: 1.0
 */

class A implements Callable {

    @Override
    public Object call() throws Exception {
        System.out.println("callable");
        return "真不会呀";
    }
}

public class Demo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        FutureTask futureTask = new FutureTask<>(new A());
//        new Thread(futureTask).start();
//        System.out.println(futureTask.get());

//        无返回值的completableFuture
//        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
//            System.out.println("hello");
//        });
//        CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> 1024)
//                .thenApply(f -> {
//                    System.out.println(f);
//                    int i = 1/0;
//                    return f * 2;
//                }).exceptionally(t->{
//                    System.out.println(t);
//                    return 404;
//                });
//        CompletableFuture<Void> hello_word = CompletableFuture.runAsync(() -> {
//            System.out.println("hello word");
//        });

//        CompletableFuture<String> completableFutureA = CompletableFuture.supplyAsync(() -> "hello");
//        //  创建对象B。
//        CompletableFuture<Void> completableFutureB = completableFutureA.thenAcceptAsync(c -> {
//            try {
//                Thread.sleep(3000);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//            System.out.println(c + "B");
//        });
//        //  创建对象C。
//        CompletableFuture<Void> completableFutureC = completableFutureA.thenAcceptAsync(c -> {
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//            System.out.println(c + "C");
//        });
////        CompletableFuture.anyOf(hello_word,completableFuture).join();
//        System.out.println(completableFutureB.get());
//        System.out.println(completableFutureC.get());

    }

}
